<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>路线管理</title>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css"></link>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/xtheme-slate.css"></link>
<script src="../ext/adapter/ext/ext-base.js"></script>
<script src="../ext/ext-all.js"></script>
<script src="../ext/src/locale/ext-lang-zh_CN.js"></script>	
<script src="../ext/base/PagingMemoryProxy.js"></script>
<script type="text/javascript">
			Ext.onReady(function(){
				Ext.Ajax.on('requestcomplete',checkUserSessionStatus, this);      
				function checkUserSessionStatus(conn,response,options){      
				    if(response.getResponseHeader('sessionstatus')){      
				    	parent.location.href='/xdj/index.jsp';   
				    }      
				}  
				Ext.BLANK_IMAGE_URL='ext/resources/images/default/s.gif';
				var cm=new Ext.grid.ColumnModel([
				    new Ext.grid.RowNumberer(),  //自动增加序列号
				    //sm, //加到每列的前边
				    {header:'路线名称',dataIndex:"lineName",sortable:true}, //True表示为可在该列上进行排列
				    {header:'是否强制顺序',dataIndex:"isCHKOrder"},
				    {header:'路线描述',dataIndex:"lineDesc"},
				    {header:'专业',dataIndex:"professName"},
				    {header:'lineID',dataIndex:"lineID",hidden:true},
				    {header:'professID',dataIndex:"professID",hidden:true}
				]);//定义相应的列模型
				var store=new Ext.data.JsonStore({
				 	url: 'chkline_load',
				 	//autoLoad : true,
				 	 root: 'result',
				 	// idProperty:'id',
					totalProperty:'totalProperty',
				    fields: ["lineName", "isCHKOrder","lineDesc","professName","lineID","professID"]
				});//存储前两项的定义的东西，将其连接起来
				                         	
				var panel = new Ext.grid.GridPanel({
					region:'center',
					border:false,
				    cm:cm,
				    //sm:sm,
				    store:store,
				   height:document.body.clientHeight,  //设置表格的高度 true为自动获取表格的大小
				    renderTo:'grid' , //渲染容器
				    enableColumnMove:false,//不可以使表格列移动
				    enableColumnResize:false, //不可以改变列的宽度
				    stripeRows:false, //True表示为显示行的分隔符
				    loadMask:true,  //会有一个Ext.LoadMask的遮罩效果
				    trackMouseOver : true,  //True表示为鼠标移动时高亮显示（默认为true）。
				    enableDragDrop : true,
				    viewConfig:{
				      forceFit:true //让没列自动填满表格，根据你设置的宽度按比例分配
				    },
				    tbar:[{
				    	text: "删除",disabled:true,id:'cDeleteBox',
				    	icon:'../image/public/user_delete.png',
				    	handler:function() {
				    		Ext.MessageBox.confirm("提示","您确定要删除这些信息吗?", function(button,text){   
				    			if(button=='yes'){
				    				var record=panel.getSelectionModel().getSelected();
				    				if(record==null) {
										alert("请您选择要删除的路线信息");
									}else{
										Ext.Ajax.request({
											url:'chkline_delete',
											success:function(response){
												var result = Ext.util.JSON.decode(response.responseText);
												if(result.success==true){
													store.load({});
												}else{
													Ext.Msg.alert("提示","操作失败，请重试。") ;
												}
											},
											params:{lineID:record.get("lineID")}
										});
									}
									
				    			}
				    			}); 
				    	}
					},{
						text: "修改",disabled:true,id:'cModifyBox',
						icon:'../image/public/user_edit.png',
						handler:function() {
							Ext.MessageBox.confirm("提示","您确定要修改这些信息吗?", function(button,text){   
								if(button=='yes'){
									Ext.getBody().unmask();
									var record=panel.getSelectionModel().getSelected();
									if(record==null) {
										alert("请您选择要修改的路线信息");
									}else{
										showWindown("chkline_update");
						        		userform.getForm().setValues({
						        			"chkLine.lineName" : record.get("lineName"),
						        			"chkLine.isCHKOrder" : record.get("isCHKOrder")=="是"?true:false,
						        			"chkLine.profess.professID": record.get("professID") ,
						        			"chkLine.lineDesc": record.get("lineDesc") ,
						        			"chkLine.chkLineID": record.get("lineID")
						        		});
									}
					        		
								}
								}); 
	
						}
						
					},{
				    	text: '增加',disabled:true,id:'cAddBox',
				    	icon:'../image/public/user_add.gif',
				        handler:function(){
				        	Ext.getBody().mask();
				        	showWindown("chkline_save");
				        }
					}],
				    bbar:new Ext.PagingToolbar({
				    	pageSize : 10, //每页显示几条
						store : store,
						beforePageText:"当前第",   
			            afterPageText:"页，共{0}页",   
			            lastText:"尾页",   
			            nextText :"下一页",   
			            prevText :"上一页",   
			            firstText :"首页",                           
				        displayInfo:true, 
				        displayMsg:'显示第{0}条数据到{1}条数据,一共有{2}条', 
				        emptyMsg:'没有记录'
				  })
				 });
				store.load({params:{start:0,limit:10}});
				function showWindown(urlString) {
					userform=new Ext.form.FormPanel({
					frame:true,
					height:250,
					buttonAlign:'top',
					layout:'form',
					items:[{
						fieldLabel:'路线名称',
						xtype:'textfield',
						allowBlank:false,
						blankText:'不能为空',
						name:'chkLine.lineName'
					},{
						fieldLabel:'巡检顺序',
						boxLabel:'是否强制顺序',
						xtype:'checkbox',
						name:'chkLine.isCHKOrder'
					},{
						xtype:'combo',
						fieldLabel: '专业',
		                hiddenName:'chkLine.profess.professID',
		                emptyText:'--请选择--',
		                forceSelection: true,
		                listWidth: 150,
		                store: professStore,
		                valueField:'professID',
		                displayField:'professName',
		                typeAhead: true,
		                mode: 'local',
		                triggerAction: 'all',
		                selectOnFocus:true,
		                allowBlank:false
					},{
						fieldLabel:'路线描述',
						xtype:'textarea',
						width:200,
						height:50,
						grow:true, //可自动增长
						preventScrollbars:true,  //不显示那个下拉条 必须与grow一起用
						name:'chkLine.lineDesc'
					},{
						xtype:'hidden',
						name:'chkLine.chkLineID'
					}
					],
					buttons:[{
						text: "确认",
					       handler:function(){ 
					    	  // alert("----------") ;
						    	//alert(userform.getForm().findField("chkLine.isCHKOrder").getValue());
					    	   if ( userform.getForm().isValid() ){
					    	    userform.form.submit({
					        	waitMsg : '正在提交数据....',   
					            url:urlString,   
					            method:'post', 
						            success:function(userform,action){  
						            	var result = Ext.util.JSON.decode(action.response.responseText);
						            	if(result.success==true) {
						            		if(urlString=="chkline_save"){
						            			win.close();
						            			store.load({});
						            			Ext.getBody().unmask();
						            		}else if(urlString=="chkline_update"){
						            			win.close() ;
						            			store.load({});
						            			Ext.getBody().unmask();
						            		}
						            		
						            	}else{
						            		Ext.Msg.alert("提示","操作失败，请重试。") ;
						            	}
						            }
						          }); 
						       }
						       }
				     },{
				        text: "取消",
				        handler:function(){ 
				           	win.close() ;
				           	Ext.getBody().unmask();
				        }
				     }]
					});
					var win=new Ext.Window({
							title:'添加路线',
							 width:400,
							 height:300,
							 items:[userform],
							 xtype:'form',
							 listeners:{"beforedestroy":function(obj)
				                 { 
								 Ext.getBody().unmask();  
				                    // obj.show(); return false; 
				                  }
							}  
					});
					win.show();
				}
				
				 new Ext.Viewport({  
					layout : 'border', // 使用border布局  
					border:false,
					items:[panel],
					listeners:{
						'beforerender' : function(cmp) {
							// set role
							var store=new Ext.data.JsonStore({
								url: '../system/role_loadFunc?funcCode=ControlCHKLine',
								autoLoad : true,
								fields: ["functioncode"]
							});
							store.load({
							    callback: function(records, options, success){
							    	var i=0;
							    	for(; i<records.length; i++) {
							    		var id = records[i].get("functioncode");
							    		//alert('d'+Ext.getCmp('56').text);
							    		if(Ext.getCmp(id)!=null) {
							    			Ext.getCmp(id).setDisabled(false);
							    		}
							        }
							    },
							    scope: store
							});
						}
					}
				 }); 
				 
				 var professStore = new Ext.data.JsonStore({
					 url:"../base/profess_load",
					 autoLoad : true,
					 fields:["professID","professName"]
				 });
				
			});
			
			
	</script> 
</head>
<body>
<div id="grid"></div>
</body>
</html>